﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Editor;
using ITAP.ShprossesBuilder.Modelling.Components;
using ITAP.ShprossesBuilder.Properties;
using System.Drawing;

namespace ITAP.ShprossesBuilder.Operations
{
    public class OperationRotateComponent : IOperation
    {
        #region IOperation Members

        public string Name
        {
            get { return "Вращать профиль"; }
        }

        public OperationGroup OperationGroup
        {
            get { return OperationGroup.ShprossOperation; }
        }

        public void Execute(ModelControl modelControl)
        {
            RotateComponentForm rotateComponentForm = new RotateComponentForm();
            if (rotateComponentForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (IComponent innerComponent in modelControl.ModelContainer.AllInnerComponents)
                {
                    if (innerComponent.Selected && innerComponent is Shpross)
                    {
                        IComponent componentToRotate = null;
                        if (rotateComponentForm.RotateWithCopy)
                        {
                            componentToRotate = (IComponent)innerComponent.Clone();
                            innerComponent.Parent.AddInnerComponent(componentToRotate);
                        }
                        else
                            componentToRotate = innerComponent;
                        componentToRotate.Rotate(rotateComponentForm.Angle.Value, componentToRotate.Parent.BoundingBox);
                    }
                }
            }
        }

        #endregion

        #region IOperation Members


        public System.Drawing.Image Thumbnail
        {
            get 
            {
                return Resources.RotateShprosses.ToBitmap();
            }
        }

        #endregion

        #region IOperation Members


        public bool CanUndo
        {
            get { return true; }
        }

        #endregion
    }
}
